# Assembler .pm
# GASL/N10
#
# Copyright Matthew F. Rienzo, 2014
#
# Based off the compiler for Poolang, which is Copryright Matthew Caswell, 2013

package GASL::Assembler;

use strict;
use Data::Dumper;

use GASL::Exception;

# Register opcodes
my $_RegsOpcode = {
  "\x00" => "i0",
  "i0" => "\x00",
  "\x01" => "i1",
  "i1" => "\x01",
  "\x02" => "i2",
  "i2" => "\x02",
  "\x03" => "i3",
  "i3" => "\x03",
  "\x04" => "i4",
  "i4" => "\x04",
  "\x05" => "i5",
  "i5" => "\x05",
  "\x06" => "i6",
  "i6" => "\x06",
  "\x07" => "i7",
  "i7" => "\x07",
  "\x08" => "i8",
  "i8" => "\x08",
  "\x09" => "i9",
  "i9" => "\x09",
  "\xA0" => "a0",
  "a0" => "\xa0",
  "\xA1" => "a1",
  "a1" => "\xa1",
  "\xA2" => "a2",
  "a2" => "\xa2",
  "\xA3" => "a3",
  "a3" => "\xa3",
  "\xA4" => "a4",
  "a4" => "\xa4",
  "\xA5" => "a5",
  "a5" => "\xa5",
  "\xA6" => "a6",
  "a6" => "\xa6",
  "\xA7" => "a7",
  "a7" => "\xa7",
  "\xA8" => "a8",
  "a8" => "\xa8",
  "\xA9" => "a9",
  "a9" => "xa9",
  "\xB0" => "s0",
  "s0" => "\xb0",
  "\xB1" => "s1",
  "s1" => "\xb1",
  "\xB2" => "s2",
  "s2" => "\xb2",
  "\xB3" => "s3",
  "s3" => "\xb3",
  "\xB4" => "s4",
  "s4" => "\xb4",
  "\xB5" => "s5",
  "s5" => "\xb5",
  "\xB6" => "s6",
  "s6" => "\xb6",
  "\xB7" => "s7",
  "s7" => "\xb7",
  "\xB8" => "s8",
  "s8" => "\xb8",
  "\xB9" => "s9",
  "s9" => "\xb9",
  "\xC0" => "r0",
  "r0" => "\xc0",
  "\xC1" => "r1",
  "r1" => "\xc1",
  "\xC2" => "r2",
  "r2" => "\xc2",
  "\xC3" => "r3",
  "r3" => "\xc3",
  "\xC4" => "r4",
  "r4" => "\xc4",
  "\xC5" => "r5",
  "r5" => "\xc5",
  "\xC6" => "r6",
  "r6" => "\xc6",
  "\xC7" => "r7",
  "r7" => "\xc7",
  "\xC8" => "r8",
  "r8" => "\xc8",
  "\xC9" => "r9",
  "r9" => "\xc9",
  "\xD0" => "f0",
  "f0" => "\xd0",
  "\xD1" => "f1",
  "f1" => "\xd1",
  "\xD2" => "f2",
  "f2" => "\xd2",
  "\xD3" => "f3",
  "f3" => "\xd3",
  "\xD4" => "f4",
  "f4" => "\xd4",
  "\xD5" => "f5",
  "f5" => "\xd5",
  "\xD6" => "f6",
  "f6" => "\xd6",
  "\xD7" => "f7",
  "f7" => "\xd7",
  "\xD8" => "f8",
  "f8" => "\xd8",
  "\xD9" => "f9",
  "f9" => "\xd9",
};
  
# Registers (this is a long one!)
my $__VM_REGS = {
  'r0' => 1,
  'r1' => 1,
  'r2' => 1,
  'r3' => 1,
  'r4' => 1,
  'r5' => 1,
  'r6' => 1,
  'r7' => 1,
  'r8' => 1,
  'r9' => 1,
  's0' => 1,
  's1' => 1,
  's2' => 1,
  's3' => 1,
  's4' => 1,
  's5' => 1,
  's6' => 1,
  's7' => 1,
  's8' => 1,
  's9' => 1,
  'a0' => 1,
  'a1' => 1,
  'a2' => 1,
  'a3' => 1,
  'a4' => 1,
  'a5' => 1,
  'a6' => 1,
  'a7' => 1,
  'a8' => 1,
  'a9' => 1,
  'f0' => 1,
  'f1' => 1,
  'f2' => 1,
  'f3' => 1,
  'f4' => 1,
  'f5' => 1,
  'f6' => 1,
  'f7' => 1,
  'f8' => 1,
  'f9' => 1,
  'i0' => 1,
  'i1' => 1,
  'i2' => 1,
  'i3' => 1,
  'i4' => 1,
  'i5' => 1,
  'i6' => 1,
  'i7' => 1,
  'i8' => 1,
  'i9' => 1,
};

# compile($) -- Organizes arguments and calls Interperet($classHandle, $dbg)
sub compile{
  my ($dbg, $inFile, $outFile) = @_;
  
  my($inClassFile, $outClassFile) = ($inFile, $outFile);
  
  
  $dbg == 1 && print "[DBG] Opening inClassFile: $inClassFile\n";
  
  local *ClassFileHandle;
  open ClassFileHandle, $inClassFile
  or die "[error] GASL: $inClassFile: ".FAILED_TO_OPEN_CLASS." : $!\n";
  
  my $classHandle = \*ClassFileHandle;
  
  $dbg == 1 && print "[DBG] Starting assembler...\n";
  (my $GASLedPackageRef, $dbg) = Interperet($classHandle, $dbg, $outClassFile);
  
  $dbg == 1 && print "[DBG] Opening outClassFile: $outClassFile\n";
  
  local *NewClassHandle;
  open NewClassHandle, ">$outClassFile"
    or die "[error] ($dbg ? : $outClassFile: ".FAILED_TO_OPEN_CLASS." : $!\n";
  
  $dbg == 1 && print "[DBG] Unloading class...\n";
  
  print NewClassHandle ${$GASLedPackageRef};
  
  close NewClassHandle;

  $dbg == 1 && print "[DBG] Done";  
  exit(0);
}

# Interperet($classHandle, $dbg) -- Interperets and constructs the program
# -- returns a string reference to the compiled code
sub Interperet($){
  my($classHandle, $dbg, $GASLExportClassFile) = @_;
  
  my $GASLClass = do{ local $/; <$classHandle> };
  
  close $classHandle;
  
  $dbg == 1 && print "[DBG] Starting GASL fragmentation\n";
  
  my @lines = grep length, split /\n/, $GASLClass;
  
  my $inHeader = 0;
  my $inVars = 0;
  my $inCode = 0;
  my $inSection = 0;
  my $headerDone = 0;
  my $varsDone = 0;
  my $inFunc = 0;
  my $inInline = 0;
  my $inlineCode;
  my $inCmp = 0;
  
  my $binary = 0;
  
  for my $index (0..$#lines){
    my $lineNu = $index+1;
    my @thisline = grep length, split /[\s]/, $lines[$index];
    my @typic = grep length, split /[\(\)]/, $lines[$index];
    my @lineChar = split '', $thisline[0];
    
    # This is for a later version of GASL
    my @methodic = grep length, split /[\{\}]/, $lines[$index];
    my @newl = grep length, split /\n/, $lines[$index];
    
    
	
	if($thisline[0] ne "_end_" && $inInline == 1){
	  $inlineCode .= $lines[$index];
	}
	
    if($thisline[0] eq "[HEADER]" && $headerDone != 1 && $inInline != 1){
      $dbg == 1 && print "[DBG] Found header - line $lineNu\n";
      
	  $inHeader = 1;
	  $inSection = 1;
	  $binary = "\xff\xff";
    }elsif($thisline[0] eq ".bits" && $inHeader == 1 && $inInline != 1){
	  if($thisline[1] eq "32"){
	    $binary .= "\x00\x20";
      }else{
	    GASL::Exception::Throw(BAD_BIT_SIZE, $lineNu);
	  }
    }elsif($thisline[0] eq ".end" && $inSection == 1 && $inInline != 1){
      $dbg == 1 && print "[DBG] Found end of a section - line $lineNu\n";
	  
	  if($inHeader == 1){
	    $dbg == 1 && print "[DBG] It was the HEADER\n";
		
		$inHeader = 0;
		$headerDone = 1;
		$binary .= "\xef\xef";
	  }
	  
	  if($inVars == 1){
	    $dbg == 1 && print "[DBG] It was the VARS section\n";
		
		$inVars = 0;
		$varsDone = 1;
		$binary .= "\xe0\xf0\xe0\xf0";
	  }
	  
	  if($inCode == 1){
	    $dbg == 1 && print "[DBG] It was the CODE section\n";
		
		$inCode = 0;
		
		$binary .= "\xe0\xe0\xe0\xf0";
	  }
	  
	  $inSection = 0;
	}elsif($thisline[0] eq "[VARS]" && $inSection != 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found VARS section - line $lineNu\n";
	  
	  $inVars = 1;
	  $inSection = 1;
	  $binary .= "\xf0\xf0\xf0\xe0";
	}elsif($lineChar[0] eq "*" && $inVars == 1){	  
	  $dbg == 1 && print "[DBG] Found varname - line $lineNu\n";
	  
	  my $varname = join('', @lineChar[1..$#lineChar]);
	  my $var = join(' ', @thisline[1..$#thisline]);
	  
	  $binary .= "\x00\x00\x00\x00\xa0$varname\xa0\x00\x00\x00\x00\xa0$var\xa0";
	}elsif($thisline[0] eq "[CODE]" && $inSection != 1){
	  $dbg == 1 && print "[DBG] Found CODE section - line $lineNu\n";
	  
	  $inCode = 1;
	  $inSection = 1;
	  $binary .= "\xf0\xf0\xf0\xd0";
	}elsif($lineChar[0] eq '.' && $inCode == 1 && $inFunc != 1){
	  $dbg == 1 && print "[DBG] Found a function - line $lineNu\n";
	  
	  $inFunc = 1;
	  
	  $binary .= "\xf0\x00\x00\x00";
	  
	  my $funcName = join('', @lineChar[1..($#lineChar - 1)]);
	  
	  $dbg == 1 && print "[DBG] Function name is $funcName\n";
	  
	  $binary .= "\xa0$funcName\xa0";
	}elsif($thisline[0] eq ".stop" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found STOP - line $lineNu\n";
	  
	  $inFunc = 0;
	  
	  $binary .= "\xe0\xe0\xe0\xe0";
	}elsif($thisline[0] eq "halt" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found HALT - line $lineNu\n";
	  
	  $binary .= "\x00\x00\x00\x00";
	}elsif($thisline[0] eq "loadi" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found LOADI - line $lineNu\n";
	  
	  $binary .= "\x10";
	  
	  my @chars = split '', $thisline[1];
	  
	  if($chars[0] eq '%'){
	    my $reg = $chars[1] . $chars[2];
		
		if(defined $__VM_REGS->{$reg}){
		  $binary .= $_RegsOpcode->{$reg};
		}else{
		  GASL::Exception::Throw(BAD_REG, $lineNu);
		}
        
		$binary .= "\xa0".$thisline[2]."\xa0";
	  }
	}elsif($thisline[0] eq "loadd" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found LOADD - line $lineNu\n";
	  
	  $binary .= "\x1A";
	  
	  my @chars = split '', $thisline[1];
	  
	  if($chars[0] eq '%'){
	    my $reg = $chars[1] . $chars[2];
		
		if(defined $__VM_REGS->{$reg}){
		  $binary .= $_RegsOpcode->{$reg};
		}else{
		  GASL::Exception::Throw(BAD_REG, $lineNu);
		}
        
		$binary .= "\xa0".join(' ', @thisline[2..$#thisline])."\xa0";
	  }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	}elsif($thisline[0] eq "add" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found ADD - line $lineNu\n";
	  
	  $binary .= "\x20";
	  
	  my @chars = split '', $thisline[1];
	  
	  my $reg1 = 0;
	  my $reg2 = 0;
	  my $reg3 = 0;
	  
	  if($chars[0] eq '%'){
	    $reg1 = $chars[1] . $chars[2];
        
		@chars = split '', $thisline[2];
		
		if($chars[0] eq '%'){
		  $reg2 = $chars[1] . $chars[2];
		  
		  @chars = split '', $thisline[3];
		  
		  if($chars[0] eq '%'){
		    $reg3 = $chars[1] . $chars[2];
		  }else{
		    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
		  }
		}else{
		  GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
		}
      }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	  
	  if(defined $__VM_REGS->{$reg1} && defined $__VM_REGS->{$reg2} && defined $__VM_REGS->{$reg3}){
	    $binary .= $_RegsOpcode->{$reg1} . $_RegsOpcode->{$reg2} . $_RegsOpcode->{$reg3};
	  }else{
	    GASL::Exception::Throw(BAD_REG, $lineNu);
	  }
	}elsif($thisline[0] eq "mov" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found MOV - line $lineNu\n";
	  
	  $binary .= "\x03\x00";
	  
	  my @chars = split '', $thisline[1];
	  
	  my $reg1 = 0;
	  my $reg2 = 0;
	    
	  if($chars[0] eq '%'){
	    $reg1 = $chars[1] . $chars[2];
        
		@chars = split '', $thisline[2];
		
		if($chars[0] eq '%'){
		  $reg2 = $chars[1] . $chars[2];  
		}else{
		  GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
		}
      }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	  
	  if(defined $__VM_REGS->{$reg1} && defined $__VM_REGS->{$reg2}){
	    $binary .= $_RegsOpcode->{$reg1} . $_RegsOpcode->{$reg2};
	  }else{
	    GASL::Exception::Throw(BAD_REG, $lineNu);
	  }
	}elsif($thisline[0] eq "call" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found CALL - line $lineNu\n";
	  
	  $binary .= "\x40\x00\x00\x00\xa0".$thisline[1]."\xa0";
	}elsif($thisline[0] eq "movv" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found MOVV - line $lineNu\n";
	  
	  $binary .= "\x04\x00\x00";
	  
	  my @chars = split '', $thisline[1];
	  my $reg = 0;
	  
	  if($chars[0] eq '%'){
	    $reg = $chars[1] . $chars[2];
		
		if(defined $_RegsOpcode->{$reg}){
		  $binary .= $_RegsOpcode->{$reg};
		}else{
		  GASL::Exception::Throw(BAD_REG, $lineNu);
		}
	  }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	  
	  @chars = split '', $thisline[2];
	  
	  my $varname = 0;
	
	  if($chars[0] eq '*'){
	    $varname = join('', @chars[1..$#chars]);
	  }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	  
	  $binary .= "\xa0".$varname."\xa0";
	}elsif($thisline[0] eq "_sl_" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found inline code - line $lineNu\n";
	  
	  $binary .= "\x05\x00\x00\x00";
	  
	  $inInline = 1;
	}elsif($thisline[0] eq "ret" && $inCode == 1 &&
	$inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found RET - line $lineNu\n";
	  
	  $binary .= "\xff\x00\xff\x00";
	}elsif($thisline[0] eq "free" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found FREE - line $lineNu\n";
	  
	  $binary .= "\x30\x00\x00";
	  
	  my @chars = split '', $thisline[1];
	  
	  if($chars[0] eq '%'){
	    my $reg = $chars[1] . $chars[2];
	    
		if(defined $_RegsOpcode->{$reg}){
		  $binary .= $_RegsOpcode->{$reg};
		}else{
		  GASL::Exception::Throw(BAD_REG, $lineNu);
		}
      }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
      }
	}elsif($thisline[0] eq "cmp" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found CMP - line $lineNu\n";
	  
	  $binary .= "\x80\x00";
	  
	  my $reg1 = 0;
	  my $reg2 = 0;
	  
	  my @chars = split '', $thisline[1];
	  
	  if($chars[0] eq '%'){
	    $reg1 = $chars[1] . $chars[2];
		
		@chars = split '', $thisline[2];
		if($chars[0] eq '%'){
		  $reg2 = $chars[1] . $chars[2];
		}else{
		  GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
		}
      }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
      }
	  
	  if(defined $_RegsOpcode->{$reg1} && defined $_RegsOpcode->{$reg2}){
	    $binary .= $_RegsOpcode->{$reg1} . $_RegsOpcode->{$reg2};
	  }else{
	    GASL::Exception::Throw(BAD_REG, $lineNu);
	  }
	  
	  $inCmp = 1;
	}elsif($thisline[0] eq "scmp" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found SCMP - line $lineNu\n";
	  
	  $binary .= "\x08\x00\x00\x00";
	  
	  if($inCmp != 1){
	    GASL::Exception::Throw(NOT_IN_CMP, $lineNu);
	  }else{
	    $inCmp = 0;
	  };
	}elsif($thisline[0] eq "cmpf" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found CMPF - line $lineNu\n";
	  
	  $binary .= "\x81\x00\x00\x00";
	  
	  $inCmp = 1;
	}elsif($thisline[0] eq "appr" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found APPR - line $lineNu\n";
	  
	  $binary .= "\x90\x00";
	  
	  my $reg1 = 0;
	  my $reg2 = 0;
	  
	  my @chars = split '', $thisline[1];
	  
	  if($chars[0] eq '%'){
	    $reg1 = $chars[1] . $chars[2];
		
		@chars = split '', $thisline[2];
		
		if($chars[0] eq '%'){
		  $reg2 = $chars[1] . $chars[2];
		}else{
		  GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
		}
      }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	  
	  if(defined $_RegsOpcode->{$reg1} && defined $_RegsOpcode->{$reg2}){
	    $binary .= $_RegsOpcode->{$reg1} . $_RegsOpcode->{$reg2};
	  }else{
	    GASL::Exception::Throw(BAD_REG, $lineNu);
	  }
	}elsif($thisline[0] eq "app" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found APP - line $lineNu\n";
	  
	  $binary .= "\x91";
	  
	  my $reg = 0;
	  
	  my @chars = split '', $thisline[1];
	  
	  if($chars[0] eq '%'){
	    $reg = $chars[1] . $chars[2];
	  }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	  
	  if(defined $_RegsOpcode->{$reg}){
	    $binary .= $_RegsOpcode->{$reg};
	  }else{
	    GASL::Exception::Throw(BAD_REG, $lineNu);
	  }
	  
	  $binary .= "\xa0".join(' ', @thisline[2..$#thisline])."\xa0"; 
	}elsif($thisline[0] eq "appv" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found APPV - line $lineNu\n";
	  
	  $binary .= "\x92";
	  
	  my $reg = 0;
	  
	  my @chars = split '', $thisline[1];
	  
	  if($chars[0] eq '%'){
	    $reg = $chars[1] . $chars[2];
	  }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	  
	  if(defined $_RegsOpcode->{$reg}){
	    $binary .= $_RegsOpcode->{$reg};
	  }else{
	    GASL::Exception::Throw(BAD_REG, $lineNu);
	  }
	  
	  @chars = split '', $thisline[2];
	  
	  my $varname = 0;
	  
	  if($chars[0] eq '*'){
	    $varname = join('', @chars[1..$#chars]);
	  }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	  
	  $binary .= "\xa0".$varname."\xa0"; 
	}elsif(join('', @lineChar[0..3]) eq "push" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found PUSH - line $lineNu\n";
	  
	  my $stack = join('', @lineChar[4..$#lineChar]);
	  
	  $binary .= "\x70\xa0".$stack."\xa0";
	  
	  $dbg == 1 && print "Stack==$stack\n";
	  
	  my $reg = 0;
	  
	  my @chars = split '', $thisline[1];
	  
	  if($chars[0] eq '%'){
	    $reg = $chars[1] . $chars[2];
	  }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	  
	  if(defined $_RegsOpcode->{$reg}){
	    $binary .= $_RegsOpcode->{$reg};
	  }else{
	    GASL::Exception::Throw(BAD_REG, $lineNu);
	  }
	}elsif(join('', @lineChar[0..2]) eq "pop" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found POP - line $lineNu\n";
	  
	  my $stack = join('', @lineChar[3..$#lineChar]);
	  
	  $dbg == 1 && print "Stack==$stack\n";
	  
	  $binary .= "\x71\xa0".$stack."\xa0";
	  
	  my $reg = 0;
	  
	  my @chars = split '', $thisline[1];
	  
	  if($chars[0] eq '%'){
	    $reg = $chars[1] . $chars[2];
	  }else{
	    GASL::Exception::Throw(SYNTAX_ERROR, $lineNu);
	  }
	  
	  if(defined $_RegsOpcode->{$reg}){
	    $binary .= $_RegsOpcode->{$reg};
	  }else{
	    GASL::Exception::Throw(BAD_REG, $lineNu);
	  }
	}elsif($thisline[0] eq "int" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Found INT - line $lineNu\n";
	  
	  $binary .= "\x5c\x00\x00\x00\xa0".$thisline[1]."\xa0";
	  
	  $dbg == 1 && print "INT==".$thisline[1]."\n";
	}elsif($thisline[0] eq "set" && $inCode == 1 && $inFunc == 1 && $inInline != 1){
	  $dbg == 1 && print "[DBG] Fount SET - line $lineNu\n";
	  
	  $binary .= "\xc5\xa0".$thisline[2]."\xa0\x00\x00\x00\x00\xa0".$thisline[1]."\xa0";
	  
	  $dbg == 1 && print "INT==".$thisline[2]." ,, ".$thisline[1]."\n";
	}
	
	if($thisline[0] eq "_end_" && $inInline == 1){
	  $binary .= "\xa0$inlineCode\xa0";
	  $inlineCode = "";
	  $inInline = 0;
	}
  }
  
  return \$binary;
}

# __END Compiler
1;
